/* 
 * 
 * Created on 14 Oct 2011 by simonk
 * 
 * Copyright: Multicom Products Ltd. 2011 Bristol, England
 */
package actions;

import java.io.File;
import java.io.IOException;

import javax.swing.JFileChooser;


import objects.data.WorkPacket;
import threading.runnable.JobSubmitter;
import utils.Utils;
import web.Hosts;
import gui.GUIUtils;
import gui.main.MainPanelGUIView;

/**
 *
 * @author simonk
 */
public class EventHandler {
	
	private static MainPanelGUIView mainPanel = GUIUtils.MainPanel;
	
	public static void passTxtKeyReleased(java.awt.event.KeyEvent evt) {                                    
		if(evt.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER && mainPanel.passTxt.getText().length() > 0) {
        	String user = mainPanel.userTxt.getText();
    		String pass = mainPanel.passTxt.getText();
    		Utils.exec.execute(new Login(user,pass));
        }
    }                                   

    public static void userTxtKeyReleased(java.awt.event.KeyEvent evt) {                                    
    	if(evt.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER && mainPanel.passTxt.getText().length() > 0) {
        	String user = mainPanel.userTxt.getText();
    		String pass = mainPanel.passTxt.getText();
    		Utils.exec.execute(new Login(user,pass));
        }
    }                                   

    public static void resultsDirBMouseClicked(java.awt.event.MouseEvent evt) {                                         
        JFileChooser fileChooser = GUIUtils.fileChooser;
        fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int returnVal = fileChooser.showOpenDialog(mainPanel.getFrame());
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fileChooser.getSelectedFile();
            mainPanel.resultsDirTxt.setText(file.getAbsolutePath());
        }
    }                                        

    public static void loginBMouseClicked(java.awt.event.MouseEvent evt) {                                    
    	if(mainPanel.loginB.getText().equals("Login")) {
    		String user = mainPanel.userTxt.getText();
    		String pass = mainPanel.passTxt.getText();
    		Utils.exec.execute(new Login(user,pass));
    	} else {
    		Login.doLogout();
    	}
    }                                   

    public static void jobDirBMouseClicked(java.awt.event.MouseEvent evt) {                                     
    	 JFileChooser fileChooser = GUIUtils.fileChooser;
         fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
         int returnVal = fileChooser.showOpenDialog(mainPanel.getFrame());
         if (returnVal == JFileChooser.APPROVE_OPTION) {
             File file = fileChooser.getSelectedFile();
             mainPanel.jobDirTxt.setText(file.getAbsolutePath());
         }
    }                                    

    public static void PbsBMouseClicked(java.awt.event.MouseEvent evt) {                                  
    	 JFileChooser fileChooser = GUIUtils.fileChooser;
         fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
         int returnVal = fileChooser.showOpenDialog(mainPanel.getFrame());
         if (returnVal == JFileChooser.APPROVE_OPTION) {
             File file = fileChooser.getSelectedFile();
             mainPanel.PbsTxt.setText(file.getAbsolutePath());
         }
    }                                 

    public static void onceRadioMouseClicked(java.awt.event.MouseEvent evt) {  
    	if(mainPanel.replayRadio.isSelected()) {
    		mainPanel.replayRadio.setSelected(false);
    	} else {
    		mainPanel.replayRadio.setSelected(true);
    	}
    }                                      

    public static void replayRadioMouseClicked(java.awt.event.MouseEvent evt) {                                         
    	if(mainPanel.onceRadio.isSelected()) {
    		mainPanel.onceRadio.setSelected(false);
    	} else {
    		mainPanel.onceRadio.setSelected(true);
    	}
    }                                        

    public static void PrefPanelMouseClicked(java.awt.event.MouseEvent evt) {                                       
        // TODO add your handling code here:
    }                                      

    public static void optRadioMouseClicked(java.awt.event.MouseEvent evt) {                                      
    	if(mainPanel.assignRadio.isSelected()) {
    		mainPanel.assignRadio.setSelected(false);
    	} else {
    		mainPanel.assignRadio.setSelected(true);
    	}
    }                                     

    public static void resultsBackChkMouseClicked(java.awt.event.MouseEvent evt) {                                            
        if(mainPanel.resultsDirTxt.isEnabled()) {
        	mainPanel.resultsDirTxt.setEnabled(false);
        } else {
        	mainPanel.resultsDirTxt.setEnabled(true);
        }
    }                                           

    public static void assignRadioMouseClicked(java.awt.event.MouseEvent evt) {                                         
    	if(mainPanel.optRadio.isSelected()) {
    		mainPanel.optRadio.setSelected(false);
    	} else {
    		mainPanel.optRadio.setSelected(true);
    	}
    }
    
    public static void submitBMouseClicked(java.awt.event.MouseEvent evt) {
        Utils.exec.execute(new JobSubmitter());
    }

    public static void saveBMouseClicked(java.awt.event.MouseEvent evt) {
        // TODO add your handling code here:
    }

    public static void loadBMouseClicked(java.awt.event.MouseEvent evt) {
        // TODO add your handling code here:
    }
}
